<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    #commentForm .main-container .short_table_list tbody{min-height: unset!important;}
</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container" style="padding-bottom: 500px!important;">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>申请人信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>工程信息</span><span onclick="go_to_engin_xiang()" class="colorlan" style="float: right;margin-right: 12px">查看工程概况</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=hou_gonghui','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=hou_gonghui','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_number" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">业务归属</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gui_unit_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程管理文件汇编</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_neiname" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gofuer" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">负责人联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gofutel" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本工程回款资金池信息（单位：元）</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <table class="layui-table chuantable" lay-size="sm">
                        <thead>
                        <tr>
                            <th>累计工程回款</th>
                            <th>累计工程付款</th>
                            <th>累计已收取</th>
                            <th>本工程回款可用余额</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody">
                        <tr>
                            <td><span id="engin_hougonghuimoney"></span></td>
                            <td><span id="engin_hougongzhimoneyquben"></span></td>
                            <td><span id="engin_hougonghuikoufee"></span></td>
                            <td><span id="engin_hougonghuikeyong"></span></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本次回款信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项类型</label>
                        <div class="layui-input-block">
                            <div id="shougonglei"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计工程回款含本次(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="leimoney" placeholder="自动计算" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账方式</label>
                        <div class="layui-input-block">
                            <div id="incdaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账账户</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="accid" class="layui-input accid" onclick="openPage('../public/choose_account.php?dom=accid','80%','80%')">
                            <div class="choose_div" id="accid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_account.php?dom=accid','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" id="dt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">本次回款占用销项票金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="xiaofee" id="xiaofee" placeholder="明细自动合计" readonly autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联流程</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>

        <div class="block-generic list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>关联销项票明细</span></div>
                        <div>
                            <button type="button" onclick="choose_piao_kai_list_page_gonghui()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">从开票明细选择</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>发票号码</th>
                            <th>受票单位</th>
                            <th>发票类型</th>
                            <th>价税合计(元)</th>
                            <th>已回款金额(元)</th>
                            <th>待回款金额(元)</th>
                            <th><text>*</text>本次回款占用开票金额(元)</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>收取信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>本次回款是否收取</label>
                        <div class="layui-input-block">
                            <select id="iskou" name="iskou" lay-filter="iskou">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                            <p class="error" id="iskou_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide koushi">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>选择本次收取款项类型</label>
                        <div class="layui-input-block">
                            <div class="radio-block">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="fuwu" title="待收取劳务分包服务费">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="shuifei" title="待收取税款(含利息)">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="gongjie" title="待收取工程负责人借款(含利息)">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="kuaifei" title="待收取快递费">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="qifei" title="直接收取">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide koushi">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">本次收取合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="koufee" id="koufee" placeholder="明细自动合计" readonly autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide koushi">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">累计收取合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="leikoufee" placeholder="自动计算" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
        </div>




        <div class="block-generic layui-hide fuwu_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="11">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取劳务分包服务费</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_fuwu()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择待扣劳务分包服务费</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>费用所属工程名称</th>
                            <th>款项类型</th>
                            <th>施工合同金额(元)</th>
                            <th>施工合同结算金额(元)</th>
                            <th>劳务分包服务费率(%)</th>
                            <th>累计应收取(元)</th>
                            <th>累计已收取(元)</th>
                            <th>待收取(元)</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="fuwu_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide shuifei_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="12">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取税款(含利息)</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_shuifei()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择待扣税款及利息</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>费用所属工程名称</th>
                            <th>税款承诺书名称</th>
                            <th>申请日期</th>
                            <th>销项票开票金额(元)</th>
                            <th>开票日期</th>
                            <th>税款保证金金额((元)</th>
                            <th>收取状态</th>
                            <th>款项类型</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="shuifei_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide gongjie_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="13">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取工程负责人借款(含利息)</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_gongjie()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择负责人待还借款</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>合同编号</th>
                            <th>出借方</th>
                            <th>借款金额(元)</th>
                            <th>借款期起</th>
                            <th>借款期止</th>
                            <th>放款日期</th>
                            <th>借款周期数</th>
                            <th>应还本金(元)</th>
                            <th>应还利息(元)</th>
                            <th>应还合计(元)</th>
                            <th><text>*</text>利息优惠(元)</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="gongjie_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide kuaifei_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="14">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取快递费</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_kuaifei()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择待扣快递费</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>费用所属工程名称</th>
                            <th>收寄类型</th>
                            <th>运单号</th>
                            <th>收寄日期</th>
                            <th>付款方式</th>
                            <th>快递费用(元)</th>
                            <th>收取状态</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="kuaifei_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide qifei_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="15">
                    <div class="opt-btn-group">
                        <div><span>收取明细-直接收取</span></div>
                        <div>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>费用所属工程名称</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th><text>*</text>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="qifei_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

    </div>
</form>
<script>
    var param_enginid = getQueryVariable('enginid') || 0;

    $("#commentForm").validate({
        rules: {
            zhai: {required: true},
            money: {required: true},
            dt: {required: true},
        },
        messages:{
            zhai: {required: "请输入"},
            money: {required: "请输入"},
            dt: {required: "请选择"},
        }
    });


    function choose_piao_kai_list_page_gonghui(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        openPage('../public/choose_piao_kai_list_page_gonghui.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid,'80%','80%');
    }

    function choose_koulei_fuwu(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }

        var money = parseValidNum($("#money").val() || 0) || 0;
        if(!money){
            facade.error("请先填写到账金额");return false;
        }
        openPage('../hou_gonghui/koulei_fuwu.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid,'80%','80%');
    }
    function choose_koulei_shuifei(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        var daodt = $("#dt").val();
        if(!daodt){
            facade.error("请先选择到账日期");return false;
        }
        openPage('../hou_gonghui/koulei_shuifei.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid+'&daodt='+daodt,'80%','80%');
    }
    function choose_koulei_gongjie(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        var daodt = $("#dt").val();
        if(!daodt){
            facade.error("请先选择到账日期");return false;
        }
        openPage('../hou_gonghui/koulei_gongjie.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid+'&daodt='+daodt,'80%','80%');
    }
    function choose_koulei_kuaifei(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        openPage('../hou_gonghui/koulei_kuaifei.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid,'80%','80%');
    }



    function choose_engin_one(obj){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        var domkey = $(obj).parents('tr').index();
        openPage('../public/choose_engin.php?page=hou_gonghui_one'+'&benenginid='+enginid+'&domkey='+domkey,'80%','80%');
    }


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_hou_gonghui, data:{enginid:param_enginid}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }


                var engininfo = res.data.engininfo;
                if(engininfo){
                    set_choose_btn('enginid',engininfo.id,engininfo.name);
                    $('#engin_number').val(engininfo.number);
                    $('#engin_gui_unit_name').val(engininfo.gui_unit_name);
                    $('#engin_gofuer').val(engininfo.gofuer);
                    $('#engin_gofutel').val(engininfo.gofutel);
                    if(engininfo.neiinfo){
                        $('#engin_neiname').val(engininfo.neiinfo.name);
                    }
                    $('#engin_hougonghuimoney').text(engininfo.hougonghuimoney);
                    $('#engin_hougongzhimoneyquben').text(engininfo.hougongzhimoneyquben);
                    $('#engin_hougonghuikoufee').text(engininfo.hougonghuikoufee);
                    $('#engin_hougonghuikeyong').text(engininfo.hougonghuikeyong);
                }











                xmselect_dan('shougonglei', res.data.shougonglei, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#shougonglei").find('xm-select').removeClass('error');
                    }else{
                        $("#shougonglei").find('xm-select').addClass('error');
                    }
                });

                xmselect_dan('incdaotype', res.data.incdaotype, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incdaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#incdaotype").find('xm-select').addClass('error');
                    }
                });

                short_table_opt_func('', 1);
                short_table_opt_func('', 11);
                short_table_opt_func('', 12);
                short_table_opt_func('', 13);
                short_table_opt_func('', 14);

                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><div class="houkoulei"></div></td>';
                listAddStr += '<td><input type="text" enginid="0" onclick="choose_engin_one(this)" readonly value="" class="layui-input enginid disabled"></td>';
                listAddStr += '<td><input type="number" class="layui-input koufee"></td>';
                listAddStr += '<td>';
                listAddStr += '<select class="layui-select kouxing">';
                listAddStr += '<option value="">请选择</option>';
                listAddStr += '<option value="实扣">实扣</option>';
                listAddStr += '<option value="暂扣">暂扣</option>';
                listAddStr += '</select>';
                listAddStr += '</td>';
                listAddStr += '<td><input type="text" class="layui-input shoubiao"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 15, {name:'houkoulei', data:res.data.houkoulei, value:''});


                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(iskou)', function(data){
            if(data.value == ''){
                $('#iskou_error').show().text('请选择');
                $('#iskou_error').parent().find('input').addClass('select_error');
            }else{
                $('#iskou_error').hide();
                $('#iskou_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == '是'){
                $(".koushi").removeClass('layui-hide');
            }else{
                $(".koushi").addClass('layui-hide');
            }
        });

        form.on('checkbox(koulei)', function(data){
            var arr = get_checkbox_value('koulei');
            if(in_array('fuwu', arr)){
                $(".fuwu_list_info").removeClass('layui-hide');
            }else{
                $(".fuwu_list_info").addClass('layui-hide');
            }
            if(in_array('shuifei', arr)){
                $(".shuifei_list_info").removeClass('layui-hide');
            }else{
                $(".shuifei_list_info").addClass('layui-hide');
            }
            if(in_array('gongjie', arr)){
                $(".gongjie_list_info").removeClass('layui-hide');
            }else{
                $(".gongjie_list_info").addClass('layui-hide');
            }
            if(in_array('kuaifei', arr)){
                $(".kuaifei_list_info").removeClass('layui-hide');
            }else{
                $(".kuaifei_list_info").addClass('layui-hide');
            }
            if(in_array('qifei', arr)){
                $(".qifei_list_info").removeClass('layui-hide');
            }else{
                $(".qifei_list_info").addClass('layui-hide');
            }
        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');


            data.field.enginid = get_choose_val('enginid');
            data.field.accid = get_choose_val('accid');
            data.field.koulei = get_checkbox_value('koulei').join(',');

            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                formValid('enginid');
                if(data.field.enginid == undefined || !data.field.enginid){
                    validRes = false;
                }

                if(!data.field.shougonglei){
                    $("#shougonglei").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#shougonglei").find('xm-select').removeClass('error');
                }

                if(!data.field.incdaotype){
                    $("#incdaotype").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#incdaotype").find('xm-select').removeClass('error');
                }

                formValid('accid');
                if(data.field.accid == undefined || !data.field.accid){
                    validRes = false;
                }

                if(data.field.iskou == ''){
                    $('#iskou_error').show().text('请选择');
                    $('#iskou_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#iskou_error').hide();
                    $('#iskou_error').parent().find('input').removeClass('select_error');
                }

                if(!validRes){return false;}


                if(data.field.iskou == '是'){
                    if(!data.field.koulei){
                        facade.error("选择本次收取款项类型");return false;
                    }
                }
            }


            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var piaoid = $(this).find('.nums').attr('piaoid');
                    var daihuikuan = $(this).find('.daihuikuan').val();
                    var xiaofee = $(this).find('.xiaofee').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!xiaofee){
                            throw new Error('第'+index+'行，请选择本次回款占用开票金额');
                        }
                        if(parseFloat(xiaofee) > parseFloat(daihuikuan)){
                            throw new Error('第'+index+'行，本次回款占用开票金额已超过待回款金额');
                        }
                    }

                    list.push({
                        piaoid:piaoid,
                        xiaofee:xiaofee,
                    });
                });
            } catch(e) {
                $(".list_info .listerror").find('span').text(e.message);
                $(".list_info .listerror").show();
                return false;
            }
            $(".list_info .listerror").hide();
            data.field.list = list;



            var fuwu_list = [''];
            try {
                $('#fuwu_list tr').each(function (i) {
                    var enginid = $(this).find('.name').attr('enginid');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!koufee){
                            throw new Error('第'+index+'行，请输入本次收取');
                        }
                    }

                    fuwu_list.push({
                        enginid:enginid,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".fuwu_list_info .listerror").find('span').text(e.message);
                $(".fuwu_list_info .listerror").show();
                return false;
            }
            $(".fuwu_list_info .listerror").hide();
            data.field.fuwu_list = fuwu_list;



            var shuifei_list = [''];
            try {
                $('#shuifei_list tr').each(function (i) {
                    var shuiid = $(this).find('.name').attr('shuiid');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){

                    }

                    shuifei_list.push({
                        shuiid:shuiid,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".shuifei_list_info .listerror").find('span').text(e.message);
                $(".shuifei_list_info .listerror").show();
                return false;
            }
            $(".shuifei_list_info .listerror").hide();
            data.field.shuifei_list = shuifei_list;




            var gongjie_list = [''];
            try {
                $('#gongjie_list tr').each(function (i) {
                    var jieid = $(this).find('.number').attr('jieid');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var yinghuanfee = $(this).find('.yinghuanfee').val();
                    var youfee = $(this).find('.youfee').val();
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!youfee){
                            throw new Error('第'+index+'行，请输入利息优惠');
                        }
                        if(parseFloat(youfee) > parseFloat(yinghuanfee)){
                            throw new Error('第'+index+'行，利息优惠已超过应还合计');
                        }
                    }

                    gongjie_list.push({
                        jieid:jieid,
                        houkoulei:houkoulei,
                        youfee:youfee,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".gongjie_list_info .listerror").find('span').text(e.message);
                $(".gongjie_list_info .listerror").show();
                return false;
            }
            $(".gongjie_list_info .listerror").hide();
            data.field.gongjie_list = gongjie_list;


            var kuaifei_list = [''];
            try {
                $('#kuaifei_list tr').each(function (i) {
                    var kuaiid = $(this).find('.enginname').attr('kuaiid');
                    var kuaitype = $(this).find('.enginname').attr('kuaitype');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){

                    }

                    kuaifei_list.push({
                        kuaiid:kuaiid,
                        kuaitype:kuaitype,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".kuaifei_list_info .listerror").find('span').text(e.message);
                $(".kuaifei_list_info .listerror").show();
                return false;
            }
            $(".kuaifei_list_info .listerror").hide();
            data.field.kuaifei_list = kuaifei_list;


            var qifei_list = [''];
            try {
                $('#qifei_list tr').each(function (i) {
                    var enginid = $(this).find('.enginid').attr('enginid');
                    var houkoulei = $(this).find('.houkoulei').find('input').val();
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!koufee){
                            throw new Error('第'+index+'行，请输入本次收取');
                        }
                        if(!kouxing){
                            throw new Error('第'+index+'行，请选择收取性质');
                        }
                    }

                    qifei_list.push({
                        enginid:enginid,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".qifei_list_info .listerror").find('span').text(e.message);
                $(".qifei_list_info .listerror").show();
                return false;
            }
            $(".qifei_list_info .listerror").hide();
            data.field.qifei_list = qifei_list;



            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);
            public_flow_submit(data.field, ask_flowdata_add_hou_gonghui, ask_flowdata_edit_hou_gonghui, $(this).attr('but'));

            return false;
        });

    });




    $("#money").on('input propertychange',function () {
        jisuan_leimoney();
    });
    function jisuan_leimoney(){
        var engin_hougonghuimoney = parseValidNum(parseFloat($("#engin_hougonghuimoney").text() || 0) || 0);
        var money = parseValidNum($("#money").val());

        var leimoney = parseFloat(engin_hougonghuimoney) + parseFloat(money);
        $("#leimoney").val(parseFormatNum(leimoney,2));
    }



    function get_checkbox_value(dom) {
        var obj = document.getElementsByName(dom);
        var s = [];
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked){
                s.push(obj[i].value)
            }
        }
        return s;
    }


    $('#list_list').on('input propertychange','.xiaofee',function () {
        jisuan_xiaofee_all();
    });

    function jisuan_xiaofee_all() {
        var allxiaofee = 0;
        $('#list_list tr').each(function (i) {
            var xiaofee = parseValidNum($(this).find('.xiaofee').val());
            allxiaofee = parseFloat(allxiaofee) + parseFloat(xiaofee);
        });
        $("#xiaofee").val(parseFormatNum(allxiaofee,2));
    }

    $('#fuwu_list,#shuifei_list,#gongjie_list,#kuaifei_list,#qifei_list').on('input propertychange','.koufee,.youfee',function () {
        jisuan_koufee_all();
    });

    function jisuan_koufee_all() {
        var allkoufee = 0;

        var arr = get_checkbox_value('koulei');
        if(in_array('fuwu', arr)){
            $('#fuwu_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('shuifei', arr)){
            $('#shuifei_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('gongjie', arr)){
            $('#gongjie_list tr').each(function (i) {
                var yinghuanfee = parseValidNum($(this).find('.yinghuanfee').val());
                var youfee = parseValidNum($(this).find('.youfee').val());
                var koufee = parseFloat(yinghuanfee) - parseFloat(youfee);
                $(this).find('.koufee').val(koufee);
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('kuaifei', arr)){
            $('#kuaifei_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('qifei', arr)){
            $('#qifei_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }


        var engin_hougonghuikoufee = parseValidNum(parseFloat($("#engin_hougonghuikoufee").text() || 0) || 0);
        var leikoufee = parseFloat(engin_hougonghuikoufee) + parseFloat(allkoufee);
        $("#koufee").val(parseFormatNum(allkoufee,2));
        $("#leikoufee").val(parseFormatNum(leikoufee,2));
    }

    function update_refresh_row_func() {
        render_date();
        render_from();
        jisuan_xiaofee_all();
        jisuan_koufee_all();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }



    function go_to_engin_xiang(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        openPage('../engin/xiang.php?id='+enginid);
    }
</script>
</body>
</html>
